<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div{
            width: 300px;
            height: 30px;
            background-color: pink;
            margin: 100px auto;
        }
        span{
            height: 40px;
            width: 90px;
            line-height: 30px;
            text-align: center;
            margin-left: 3px;
            display: inline-block;
            margin: auto;
        }
    </style>
</head>
<body>
    <div>
        <span class="h">00小时</span>
        <span class="m">00分钟</span>
        <span class="s">00秒</span>
    </div>

    <script>
        //获取时分秒的文档对象
        const spanHObj = document.querySelector(".h")
        const spanMObj = document.querySelector(".m")
        const spanSObj = document.querySelector(".s")
        //创建秒杀时间
        const creatTime = new Date("2023-12-1 20:00:00")
        // console.log(creatTime)
        
        function func1(){
            //获取现在时间
            const currentTime = new Date()
            //计算出距离秒杀时间还有多少秒
            const allSecond = (creatTime-currentTime)/1000

            //计算出秒
            let s = parseInt(allSecond%60)
            spanSObj.innerHTML = s+'秒'
            //分
            let m = parseInt(allSecond/60%60)
            spanMObj.innerHTML = m+'分钟'
            //时
            let h = parseInt(allSecond/60/60)
            spanHObj.innerHTML = h+'小时'

        }
            setInterval(func1,1000)
        
    </script>
</body>
</html>